package com.snopy.concurrency.methodstack;

import lombok.extern.slf4j.Slf4j;
import org.openjdk.jol.info.ClassLayout;

import java.util.concurrent.TimeUnit;

/**
 * @author snopy
 * @version 1.0.0
 * @classname Demo
 * @description
 * @email 77912204@qq.com
 * @date 2022/06/23 18:26
 */
@Slf4j
public class Demo {
    static final Object lock = new Object();
    public static void main(String[] args) throws InterruptedException {
        log.info("n1:{}",ClassLayout.parseInstance(lock).toPrintable());
        synchronized (lock){
            TimeUnit.SECONDS.sleep(1);
            log.info("n1:{}",ClassLayout.parseInstance(lock).toPrintable());

        }

        new Thread(()->{
                 for (int i = 0; i < 20; i++) {
                        synchronized (lock) {
                            try {
                                Thread.sleep(100);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                            log.info("n2:{}",ClassLayout.parseInstance(lock).toPrintable());
                        }

                 }
            }).start();
            new Thread(()->{
                for (int i = 0; i < 20; i++) {
                    synchronized (lock) {
                        try {
                            Thread.sleep(100);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        log.info("n3:{}",ClassLayout.parseInstance(lock).toPrintable());
                    }

                }
            }).start();

        log.info("n4:{}",ClassLayout.parseInstance(lock).toPrintable());
        TimeUnit.SECONDS.sleep(5);
        log.info("n1:{}",ClassLayout.parseInstance(lock).toPrintable());
        log.info("n1:{}",ClassLayout.parseInstance(new NumOperator()).toPrintable());
    }
}
